package com.baidu.controller;

import com.baidu.pojo.TbBrand;
import com.baidu.service.TbBrandService;
import com.baidu.utils.ResultResponse;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 品牌管理
 */
@RestController
@RequestMapping("/brand")
@CrossOrigin
public class TbBrandController {
    @Autowired
    TbBrandService tbBrandService;

    /**
     * 品牌管理列表
     * @param pageNum 分页
     * @param pageSize 分页
     * @return
     */
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultResponse findTbBrandList(@PathVariable("pageNum") Integer pageNum,
                                          @PathVariable("pageSize") Integer pageSize){

        return tbBrandService.findTbBrandList(pageNum,pageSize);
    }

    /**
     * 品牌管理添加
     * @param tbBrand
     * @return
     */
    @PostMapping("/save")
    public ResultResponse saveTbBrand(@RequestBody TbBrand tbBrand){
        tbBrandService.saveTbBrand(tbBrand);
        return ResultResponse.SUCCESS();
    }

    /**
     * 品牌管理回显
     * @param id
     * @return
     */
    @PostMapping("/queryTbBrandById/{id}")
    public ResultResponse queryTbBrandById(@PathVariable("id") Long id){
        TbBrand tbBrand=tbBrandService.queryTbBrandById(id);
        return ResultResponse.SUCCESS(tbBrand);
    }

    /**
     * 品牌管理修改
     * @param tbBrand
     * @return
     */
    @PostMapping("/set")
    public ResultResponse updateTbBrand(@RequestBody TbBrand tbBrand){
        tbBrandService.updateTbBrand(tbBrand);
        return ResultResponse.SUCCESS();
    }

    /**
     * 品牌管理删除
     * @param ids
     * @return
     */
    @PostMapping("/del")
    public ResultResponse delTbBrandById(@RequestBody List<TbBrand> ids){
        return tbBrandService.delTbBrandById(ids);
    }

    //品牌管理列表
    @GetMapping("/list")
    public ResultResponse findBrandList(){
        List<TbBrand> tbBrandList=tbBrandService.findList();
        return ResultResponse.SUCCESS(tbBrandList);
    }

}
